home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.6 KB | 332 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPolySh.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPOLYSH_H
- #include "FWPolySh.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- #ifndef FWPOLY_H
- #include "FWPoly.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphx_PolygonShape
- #endif
-
- //========================================================================================
- // class FW_CPolygonShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPolygonShape)
- FW_DEFINE_CLASS_M1(FW_CPolygonShape, FW_CShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::FW_CPolygonShape
- //----------------------------------------------------------------------------------------
-
- FW_CPolygonShape::FW_CPolygonShape(const FW_CPolygon& polygon,
- FW_ERenderVerbs renderVerb,
- FW_Boolean autoCloseFrame,
- const FW_CInk& ink,
- const FW_CStyle& style) :
- FW_CShape(renderVerb, ink, style, FW_kNormalFont),
- fPolygon(polygon),
- fAutoCloseFrame(autoCloseFrame)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::FW_CPolygonShape
- //----------------------------------------------------------------------------------------
-
- FW_CPolygonShape::FW_CPolygonShape(const FW_CPolygonShape& other) :
- FW_CShape(other),
- fPolygon(other.fPolygon),
- fAutoCloseFrame(other.fAutoCloseFrame)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::FW_CPolygonShape
- //----------------------------------------------------------------------------------------
-
- FW_CPolygonShape::FW_CPolygonShape(FW_CReadableStream& stream) :
- FW_CShape(stream)
- {
- stream >> fPolygon;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::~FW_CPolygonShape
- //----------------------------------------------------------------------------------------
-
- FW_CPolygonShape::~FW_CPolygonShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CPolygonShape& FW_CPolygonShape::operator=(const FW_CPolygonShape& other)
- {
- fPolygon = other.fPolygon;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::SetAutoCloseFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::SetAutoCloseFrame(FW_Boolean autoCloseFrame)
- {
- fAutoCloseFrame = autoCloseFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::GetAutoCloseFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPolygonShape::GetAutoCloseFrame() const
- {
- return fAutoCloseFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::Render(FW_CGraphicContext& gc) const
- {
- FW_PrivRenderPolygon(gc.GetEnvironment(),
- gc,
- fPolygon,
- GetRenderVerb(),
- fAutoCloseFrame,
- fInk,
- fStyle);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPolygonShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- FW_UNUSED(gc);
-
- if(fRenderVerb == FW_kNoRendering)
- return FALSE;
-
- // Quickly check the bounds
- FW_CRect bounds;
- fPolygon.GetBounds(bounds);
-
- bounds.Inset(-tolerance, -tolerance);
-
- if(bounds.Contains(test))
- {
- // Bounds check out OK, now do a more thourough test
- long pointCount = fPolygon.GetCount();
- const FW_SPoint* points = fPolygon.GetPoints();
- if(fRenderVerb == FW_kFrame)
- {
- for(long i = 0; i < pointCount - 1; i ++)
- if(::FW_HitTestLine(points[i], points[i + 1], test, tolerance))
- return TRUE;
- }
- else
- return ::FW_HitTestPolygon(pointCount, points, test);
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CPolygonShape::Copy() const
- {
- return FW_NEW(FW_CPolygonShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::Transform(Environment *ev, ODTransform* transform)
- {
- fPolygon.Transform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::InverseTransform(Environment *ev, ODTransform* transform)
- {
- fPolygon.InverseTransform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- fPolygon.Move(deltaX, deltaY);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- fPolygon.MoveTo(x, y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::Inset(FW_Fixed x, FW_Fixed y)
- {
- fPolygon.Inset(x, y);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- fPolygon.GetBounds(rect);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CPolygonShape::GetAnchorPoint() const
- {
- FW_CRect rect;
- fPolygon.GetBounds(rect);
-
- return rect.TopLeft();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CShape::Flatten(stream);
-
- stream << fPolygon;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::RenderPolygon
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::RenderPolygon(FW_CGraphicContext& gc,
- const FW_CPolygon& polygon,
- FW_ERenderVerbs renderVerb,
- FW_Boolean autoCloseFrame,
- const FW_CInk& ink,
- const FW_CStyle& style)
- {
- FW_PrivRenderPolygon(gc.GetEnvironment(),
- gc,
- polygon,
- renderVerb,
- autoCloseFrame,
- ink,
- style);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::GetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::GetGeometry(FW_CPolygon& polygon) const
- {
- polygon = fPolygon;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPolygonShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CPolygonShape::SetGeometry(const FW_CPolygon& polygon)
- {
- fPolygon = polygon;
- }
-
-